<template>
  <el-cascader
      size="mini"
      :options="treeData"
      :props="props"
      separator="-"
  />
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue/dist/vue.esm-bundler.js'
import { getDepartmentInfo } from '@/api/employee'
import { transListToTreeData } from '@/utils/index'

const treeData = ref<any[]>([])

onMounted(async () => {
  try {
    const res = await getDepartmentInfo()
    treeData.value = transListToTreeData(res.data)
  } catch (error) {
    console.error('Failed to get department info:', error)
  }
})

const props = withDefaults(defineProps<{
  label?: string
  value?: string
}>(), {
  label: 'name',
  value: 'id'
})
</script>

<style scoped>
</style>

